
forget pabBuf    
create pabBuf 32 chars allot    \ buffer to build PAB in
create dsrlnkVEC                \ vector for BLWP instruction 
    $A156 ,                     \ DSRLNK workspace for BLWP
    $6A16 ,                     \ DSRLNK entry point for BLWP
    
hex code: (opt5) ( -- ) 
0200 1409 C800 8356 04E0 6000 0420 dsrlnkVEC ,
0008 06A0 67BE 04E0 6002 ;code decimal

: (pab) ( "filename" size opcode -- )
    here >r             \ save HERE (want to use comma!)
    pabBuf H !          \ set compilation address
    c,                  \ opcode (from stack)
    0 c,                \ not used for open command
    $1420 ,             \ program destination address in VDP
    0 ,                 \ these two bytes not used
    8192 min ,          \ # of bytes to transfer (from stack)
    0 c,                \ not used
    22 min              \ restrict length of filename 
    dup c,              \ length of filename
    r> h !              \ restore HERE
    pabBuf 10 + swap .s cmove      \ move filename
    $1400 pabBuf 32 vmbw ;      \ write pab to VDP

: opt5Load ( "filename" -- )    
  \ Load an ED/AS Option 5 (program image) file 
  \ e.g. S" DSK1.MYFILE" opt5Load
  \ the file cannot be larger than 8192 bytes
  \ the program image file is loaded into VDP memory
  \ starting at >1420.
    8192 5 (pab)        \ build the PAB. 5=opcode LOAD
    (opt5)              \ call assembler code 
    ioerr abort" Cannot load file" ;
    
: opt5Save ( "filename" size -- )
    \ saves up to 8192 bytes starting at VDP address >1420 
    \ to a program image file. 
    6 (pab)             \ build the PAB. 6=opcode SAVE
    (opt5) ;
true unsigned ! hex
s" DSK3.JETPAC" opt5Load


\ ------------------------------------------------------
\ the assembler version of the above CODE: word...
asm: (opt5) ( -- )
    \ reads a program image file into VDP RAM
    r0 $1409 li,        \ address of vdp pab length byte 
    r0 $8356 @@ mov,    \ move it to >8356
    $6000 @@ clr,       \ select bank 1 in TF ROM 
    dsrlnkVEC @@ blwp,  \ call dsrlnk
    8 ,                 \ standard dsrlnk
    $67be @@ bl,        \ restore scratch TF pad code
    $6002 @@ clr,       \ select bank 0 in TF ROM 
;asm


